module.exports = function (UC, source, config, ArFor, cache, package) {
    var UserControl = UC;

    var jlanguage = config.jlanguage;
    var router = function (req, res, next) {
        params = req.params;
        if (params.Order_id || params.Link_id|| params.printer_id) {
            new source(params.source_id, params, function (db) {
                if (db.Table && db.Table.length > 0) {
                    var List = db.Table;
                    for (var i = 0; i < List.length; i++) {
                        var item = List[i];
                        if (item.language) {

                        } else {
                            item.language = config.language
                        } 
                        item.dir = 'ltr';
                        if (item.language == 'ug') {
                            item.dir = 'rtl';
                        }
                        item.datetime=new Date().Format('yyyy/MM/dd')
                        item.name = config.name;
                        List[i] = item;
                    }
                    List = List[0];
                    if(List.Printer_id==2||List.Printer_id==null){
                        res.Json({});
                        return
                    }
                    List.subs=List.subs==null?[]:List.subs;
                    var Orders = {
                        originalUrl: "",
                        Table: [],
                        getvalue: function (key, lang) {
                            var val = jlanguage.getval(key, lang)
                            return val
                        }
                    };
                    Orders = Object.assign(Orders, List);
                    cache.Render({
                        id: package.id,
                        file: './jview/' + params.view
                    }, Orders, function (str) {
                        var jstr = JSON.parse(str);
                        res.Json(jstr);
                    });
                } else {
                    res.Json({
                        "error": 1002
                    });
                }
            });
        } else {
            res.Json({
                "error": 1001
            });
        };
    };

    return router;
};